import { CHANGE_INPUT_VALUE , CLICK_CHANGE , DELETE_ITEM ,GET_LIST } from './actionTypes';
const defaultState = {
    inputValue : 'wuxianshen',
    list:[]
}
export default ( state = defaultState ,action ) => {
    console.log( state, action );
    if(action.type === CHANGE_INPUT_VALUE){
        let newState = JSON.parse(JSON.stringify(state))
        newState.inputValue = action.value
        return newState
    }

    if( action.type === CLICK_CHANGE ) {
        let newState = JSON.parse(JSON.stringify(state))
        newState.list.push(newState.inputValue)
        newState.inputValue = ''
        return newState
    }

    if( action.type === DELETE_ITEM ) {
        let newState = JSON.parse(JSON.stringify(state))
        newState.list.splice(action.index,1)
        return newState
    }

    if( action.type === GET_LIST ) {
        let newState = JSON.parse(JSON.stringify(state))
        newState.list = action.data.data.list
        return newState
    }
    
    return state
}